const { Sequelize } = require("sequelize");
const { isRequired } = require("../utils");

module.exports = (sequelize, DataTypes) => {
  const MapIconGroup = sequelize.define(
    "IconGroup",
    {
      id: {
        type: DataTypes.UUID,
        defaultValue: Sequelize.UUIDV4,
        //是否允许为空
        allowNull: false,
        //是否为主键
        primaryKey: true,
        //备注
        comment: "图标组id",
      },
      iconGroupName: {
        type: DataTypes.STRING,
        allowNull: false,
        comment: "组名称",
        // 设置唯一不能重复
        unique: {
          msg: "组名称已存在",
        },
        validate: isRequired("组名称"),
      },
    },
    {
      timestamps: true,
      tableName: "map_iconGroup",
      createdAt: "createTime",
      updatedAt: "updateTime",
      comment: "图标组表",
    }
  );
  MapIconGroup.associate = function (db) {
    MapIconGroup.hasMany(db.Icon, {
      foreignKey: "iconGroupId",
      as: "icons",
    });
  };
  return MapIconGroup;
};
